<template>
    <div class="information">
        <breadcrumb :routes="routes"></breadcrumb>
        <div class="infor-warper">
            <div class="dev-width">
                <h3>{{news.title}}</h3>
                <div class="infor-msg">
                    <span>{{news.updateTime | formatDate('yyyy-MM-dd')}}</span>
                    <span v-if="news.hasOwnProperty('source')">来源：{{news.source}} </span>
                    <span v-if="news.hasOwnProperty('author')">作者：{{news.author}}</span>
                </div>
                <div class="infor-detail">
                    <span v-html="news.content"></span>
                </div>
            </div>
        </div>
        <back-to-top></back-to-top>
    </div>
</template>
<script>
import portal from "~/net/portal"
import backToTop from "~/components/BackToTop"
import breadcrumb from '~/components/Breadcrumb'
export default {
    name: 'newsdetail',
    data() {
        return {
            news: {}
        }
    },
    components: {
        backToTop,
        breadcrumb
    },
    computed: {
        routes() {
            return [
                { name: '首页', path: '/' },
                { name: '资讯', path: '/news' },
                { name: this.news.category, path: '/news/catagory', query: { id: this.news.categoryId, name: this.news.category } },
                { name: '详情' }
            ]
        }
    },
    asyncData({ params, error, req }) {
        return portal.getInformationById({
            query: { id: params["id"] },
            client: req
        }).then((res) => {
            return {
                news: res.data
            }
        }).catch(e => {
            error({ statusCode: 404, messsage: '资讯不存在' })
        })
    }
}
</script>
<style>
@import "~/assets/styles/news.css";
</style>